<?php
    if(!$this->session->userdata('logged_in')) {
        redirect('logout');
    } else if($this->session->userdata('role') !== 'admin') {
        redirect('forbidden');
    }
?>
<div id="user_page">
    <div id="user_wrapper">
        <p class="p_user_heading">Users</p>
        <?php echo form_open('user/delete_update', array('id' => 'users_form')); ?>
          <div id="ud_c">
            <div id="delete_c">
              <label id="update_lbl">Delete Users: </label><br/>
              <input name="deleteB" type="submit" value="Delete Checked" id="delete_user" onclick="return confirm('Are you sure you want to delete the checked user/s?')"/></div>
            <div id="update_c">
                <label id="update_lbl">Update Role to: </label><br/>
                  <?php $roles = $this->role_m->get_all_roles();
                      foreach($roles as $row) {
                        echo '<input class="role_choice" name="role" type="radio" value=' . $row->role_id .'><span id=rb_value>' . $row->rolename . '</span>';
                      }
                  ?>
                <input name="roleB" type="submit" value="Update Checked" id="update_role" />
              </div>
          </div>
        
          <br/><br/><br/>
          <div class="wrapper">
            <table id="big_table" class="display">
              <thead>
                <tr>
                  <th></th>
                  <th>ID Number</th>
                  <th>Last Name</th>
                  <th>First Name</th>
                  <th>Middle Name</th>
                  <th>Email Address</th>
                  <th>Type</th>
                  <th>Course /Dept</th>
                  <th>Role</th>
                  <th></th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
            
          <script type="text/javascript">
              var oTable;

              $(document).ready(function()
              {
                oTable = $('#big_table').dataTable
                ({
                  'aoColumnDefs'  : [
                  { aTargets: [0],
                    fnRender: function (o, v) {
                        return '<input type="checkbox" name="user[]" value="'+v+'" />';
                    }
                  }
                  ],
                  'iCookieDuration': 60,
                  'bStateSave'     : true,
                  'bServerSide'    : true,
                  'bAutoWidth'     : true,
                  'bProcessing': true,
                  'sDom': 'T<"clear">lfrtip',
                  'oTableTools': {
                    "aButtons": [
                        {
                            "sExtends": "copy",
                            "mColumns": [1, 2, 3, 4, 5, 6, 7, 8],
                            "sTitle": "Users List"
                        },
                        {
                            "sExtends": "csv",
                            "mColumns": [1, 2, 3, 4, 5, 6, 7, 8],
                            "sTitle": "Users List"
                        },
                        {
                            "sExtends": "xls",
                            "mColumns": [1, 2, 3, 4, 5, 6, 7, 8],
                            "sTitle": "Users List"
                        },
                        {
                            "sExtends": "pdf",
                            "mColumns": [1, 2, 3, 4, 5, 6, 7, 8],
                            "sTitle": "Users List"
                        }
                    ],
                  "sSwfPath" : "<?php echo base_url();?>resources/swf/copy_csv_xls_pdf.swf"
                  },
                  'sPaginationType': 'full_numbers',
                  'sAjaxSource'    : '<?php echo base_url();?>user_c/user_list',
                  'aoColumns'      : 
                  [
                    { 'sName' : 'status'},
                    { 'sName' : 'idno'},
                    { 'sName' : 'lname'},
                    { 'sName' : 'fname'},
                    { 'sName' : 'mname'},
                    { 'sName' : 'email'},
                    { 'sName' : 'type'},
                    { 'sName' : 'course'},
                    { 'sName' : 'rolename'},
                    { 'sName' : 'edit'},
                    { 'sName' : 'delete'}
                  ],
                  'fnServerData': function(sSource, aoData, fnCallback)
                  {
                    $.ajax
                    ({
                      'dataType': 'json',
                      'type'    : 'POST',
                      'url'     : sSource,
                      'data'    : aoData,
                      'success' : fnCallback
                    });
                  },
                  "bJQueryUI": true,
                  "iDisplayStart ":20,
                  "oLanguage": {
                    "sProcessing": "<img src='<?php echo base_url();?>resources/images/ajax-loader_dark.gif'>",
                    "sSearch": "Search:"
                  }, 
                  "fnInitComplete": function() {
                    oTable.fnAdjustColumnSizing();
                  }
                });
                oTable.fnSort( [ [1,'asc'] ] );
              });
        </script>
        <?php echo form_close(); ?>
    </div>
</div>
